#!/usr/bin/lua
local json = require("cjson")

package.path = "/web/muggle/Api/package/?.lua"

saveimg = {}

ngx.req.read_body()
Post = ngx.req.get_post_args()
sign = Post['sign']  -- 文件唯一标识
content = Post['content']  -- 文件片段
fix = Post['fix']  -- 后缀名
filepath = "/web/muggle/static/public/image-base/upload-head/"
local file = io.open(filepath..sign.."."..fix, "a")
file:write(content)
file:close()

function saveimg.push()
    local result = {
        code = 0,
        mess = ngx.escape_uri("文件片段已写入"),
        datetime = os.time(),
        data = {
            filepath = "/public/image-base/upload-head/".. sign .. ".".. fix
        }
    }
    return json.encode(result)
end

return saveimg
